﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Controls_MenuVertical : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        dtlDanhMuc.DataSource = new DanhMucDAO().HienThiDanhMuc();
        dtlDanhMuc.DataBind();
        foreach (DataListItem item in dtlDanhMuc.Items)
        {
            int idDanhMuc = int.Parse(((Button)item.FindControl("btnDanhMuc")).CommandArgument);
            DataList datalist = (DataList)item.FindControl("dtlDanhMucCon");
            datalist.DataSource = new DanhMucConDAO().HienThiDanhMucCon(1, idDanhMuc);
            datalist.DataBind();
            datalist.Visible = false;
        }
        ((DataList)dtlDanhMuc.Items[0].FindControl("dtlDanhMucCon")).Visible = true;
    }

    protected void dtlDanhMuc_ItemCommand(object source, DataListCommandEventArgs e)
    {
        foreach (DataListItem item in dtlDanhMuc.Items)
        {
            int idDanhMuc = int.Parse(((Button)item.FindControl("btnDanhMuc")).CommandArgument);
            if (idDanhMuc == int.Parse(e.CommandArgument.ToString()))
            {
                ((DataList)item.FindControl("dtlDanhMucCon")).Visible = true;
            }
            else
                ((DataList)item.FindControl("dtlDanhMucCon")).Visible = false;
        }
    }
}